package edu.ptu.shortlink.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import edu.ptu.shortlink.admin.common.convention.result.Result;
import edu.ptu.shortlink.admin.common.convention.result.Results;
import edu.ptu.shortlink.admin.remote.ShortLinkRemoteService;
import edu.ptu.shortlink.admin.remote.dto.req.RecycleBinPageReqDTO;
import edu.ptu.shortlink.admin.remote.dto.req.RecycleBinSaveReqDTO;
import edu.ptu.shortlink.admin.remote.dto.resp.ShortLinkPageRespDTO;
import edu.ptu.shortlink.admin.service.IRecycleBinService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @BelongsProject: shortlink
 * @BelongsPackage: edu.ptu.shortlink.project.controller
 * @Author: HYJ
 * @CreateTime: 2025-05-01  21:30
 * @Description: 短链接回收站控制层
 * @Version: 1.0
 */
@RestController
@RequiredArgsConstructor
public class RecycleBinController {

    private final ShortLinkRemoteService shortLinkRemoteService;
    private final IRecycleBinService recycleBinService;


    /**
     * 保存短链接到回收站
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin")
    public Result<Void> saveToRecycleBin(@RequestBody RecycleBinSaveReqDTO requestParam) {
        shortLinkRemoteService.saveToRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 回收站分页查询
     */
    @GetMapping("/api/short-link/admin/v1/recycle-bin/page")
    public Result<Page<ShortLinkPageRespDTO>> pageRecycleBin(RecycleBinPageReqDTO requestParam) {
        return recycleBinService.pageRecycleBin(requestParam);
    }

    /**
     * 从回收站恢复短链接
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/recover")
    public Result<Void> recoverFromRecycleBin(@RequestBody RecycleBinSaveReqDTO requestParam) {
        shortLinkRemoteService.recoverFromRecycleBin(requestParam);
        return Results.success();
    }

    /**
     * 从回收站移除短链接
     */
    @PostMapping("/api/short-link/admin/v1/recycle-bin/remove")
    public Result<Void> removeFromRecycleBin(@RequestBody RecycleBinSaveReqDTO requestParam) {
        shortLinkRemoteService.removeFromRecycleBin(requestParam);
        return Results.success();
    }
}
